package badugaserver;
import java.util.ArrayList;

/**
 * @author Wojtek N., Kamil M.
 * @version 0.7
 * The main class of the player hand.
 */
public class Hand 
{
	private ArrayList<Card> hand = new ArrayList<Card>();
	
	public Hand(Deck deck)
	{
		for(int i = 0; i < 4; i++)
		{
			hand.add(deck.drawFromDeck());
		}

	}
	
	public ArrayList<Card> getHand()
	{
		return hand;
	}
	/**
	 * Sets a card in the place of the removed one.
	 * @param index of removed card
	 * @param card which will be set in index place.
	 */
	public void setCard(int index, Card card)
	{
		ArrayList<Card> temp = new ArrayList<Card>();
		int i = 0;
		while(temp.size() != 4)
		{
			if(i == index)
			{
				temp.add(card);
				index = -1;
			}
			else
			{
				if(index == -1)
				{
					temp.add(getCard(i-1));
				}
				else
				{
					temp.add(getCard(i));
				}
			}
			i++;
		}
		hand = temp;
	}
	/**
	 * 
	 * @param index of the card to be returned
	 * @return card of given index
	 */
	public Card getCard(int index)
	{
		return hand.get(index%size());
	}
	
	public Card removeCard(int index)
	{
		return hand.remove(index%size());
	}
	
	public int size()
	{
		return hand.size();
	}
	/**
	 * 
	 * @param which true or false
	 * @return hand as a string; if true return full name cards (fe. As of spades), else short name cards (fe. As)
	 */
	public String toString(boolean which)
	{
		String temp ="";
		for(int i=0; i<hand.size(); i++)
		{
			temp = temp + getCard(i).toString(which);
			if(i != (hand.size()-1) && which == true)
			{
				temp = temp + ", ";
			}
		}
		return temp;
	}

}
